-[ program "top.c" ]

-[ headers, begin ]
	!stdlib !stdarg extlibs parse type pfunc putil
-[ end ]

int main(int argc,char **argv) {
	utermlist_t *terms;

	pfunc_init();

#if 0
	terms= ulang_parse_file("../test/test-deepfor");
	-[ utermlist>deep-for K ∈ terms, begin ]
		if (K->kind==ut_word) {
			int i;
			for(i=0;K->data[i];i++)
				K->data[i]= toupper(K->data[i]);
		}
	-[ end ]
	printf(">>>>TEST-DEEPFOR\n");
	dump_termlist(terms);
	printf("\n<<<<<<<<TEST-DEEPFOR\n");
#endif

	run_init_code();
	
	terms= ulang_parse_file(argv[1]);
	process_termlist(terms);

	compile_user_functions();

	return 0;
}

-[private] void process_termlist(utermlist_t *terms)
{
	currentfunc_push(currentfunc, "[top-level]");
	run_pfunc_body(parser_new(terms,0));
}

-[private] void run_init_code() {
	static char initcode[]=
		{ -[quote code, begin] -[init code] -[end] };
	process_termlist(ulang_parse_string(initcode));
}
